package com.sky.wsp.rabbitmq.topic;

import com.sky.wsp.rabbitmq.topic.vo.EventTypeEnum;
import com.sky.wsp.rabbitmq.topic.vo.IDaaSMessage;
import com.sky.wsp.rabbitmq.topic.vo.UserPassword;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @desccription MQ消息消费者示例
 * @auth wangshaopeng@talkweb.com.cn
 * @date 2022/9/29
 */
@Component
public class RabbitMqTopicConsumer {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @RabbitHandler
    @RabbitListener(queues = TopicMqConfig.IDAAS_USER_PASSWORD_QUEUE)
    public void processUserPassword(IDaaSMessage msg) {
        logger.debug("processUser: {}", msg);
        EventTypeEnum eventType = msg.getEventType();
        switch (eventType) {
            case UPDATE:
                UserPassword user = (UserPassword) msg.getData();
                System.out.println("三方应用需要修改用户密码: " + user.getUsername());
                break;
            default:
                System.out.println("错误的事件类型");
                break;
        }
    }
}
